﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace web.component
{
    public class TimeZoneIdInfo {
        public string key { get; set; }
        public string value { get; set; }
        public string des { get; set; }
    }
    public class Udate_time
    {
        public Udate_time()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public static DateTime GetCurrentDateTime() {
            return DateTime.UtcNow;
        }

        public static List<TimeZoneIdInfo> ListTimeInfo()
        {
            var lst = new List<TimeZoneIdInfo>()
            {
                new TimeZoneIdInfo(){key= "1",value="Morocco Standard Time",des="(GMT) Casablanca"},
                new TimeZoneIdInfo(){key= "2",value="GMT Standard Time",des="(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London"},
                new TimeZoneIdInfo(){key= "3",value="Greenwich Standard Time",des="(GMT) Monrovia, Reykjavik"},
                new TimeZoneIdInfo(){key= "4",value="W. Europe Standard Time",des="(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna"},
                new TimeZoneIdInfo(){key= "5",value="Central Europe Standard Time",des="(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague"},
                new TimeZoneIdInfo(){key= "6",value="Romance Standard Time",des="(GMT+01:00) Brussels, Copenhagen, Madrid, Paris"},
                new TimeZoneIdInfo(){key= "7",value="Central European Standard Time",des="(GMT+01:00) Sarajevo, Skopje, Warsaw, Zagreb"},
                new TimeZoneIdInfo(){key= "8",value="W. Central Africa Standard Time",des="(GMT+01:00) West Central Africa"},
                new TimeZoneIdInfo(){key= "9",value="Jordan Standard Time",des="(GMT+02:00) Amman"},
                new TimeZoneIdInfo(){key= "10",value="GTB Standard Time",des="(GMT+02:00) Athens, Bucharest, Istanbul"},
                new TimeZoneIdInfo(){key= "11",value="Middle East Standard Time",des="(GMT+02:00) Beirut"},
                new TimeZoneIdInfo(){key= "12",value="Egypt Standard Time",des="(GMT+02:00) Cairo"},
                new TimeZoneIdInfo(){key= "13",value="South Africa Standard Time",des="(GMT+02:00) Harare, Pretoria"},
                new TimeZoneIdInfo(){key= "14",value="FLE Standard Time",des="(GMT+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius"},
                new TimeZoneIdInfo(){key= "15",value="Israel Standard Time",des="(GMT+02:00) Jerusalem"},
                new TimeZoneIdInfo(){key= "16",value="E. Europe Standard Time",des="(GMT+02:00) Minsk"},
                new TimeZoneIdInfo(){key= "17",value="Namibia Standard Time",des="(GMT+02:00) Windhoek"},
                new TimeZoneIdInfo(){key= "18",value="Arabic Standard Time",des="(GMT+03:00) Baghdad"},
                new TimeZoneIdInfo(){key= "19",value="Arab Standard Time",des="(GMT+03:00) Kuwait, Riyadh"},
                new TimeZoneIdInfo(){key= "20",value="Russian Standard Time",des="(GMT+03:00) Moscow, St. Petersburg, Volgograd"},
                new TimeZoneIdInfo(){key= "21",value="E. Africa Standard Time",des="(GMT+03:00) Nairobi"},
                new TimeZoneIdInfo(){key= "22",value="Georgian Standard Time",des="(GMT+03:00) Tbilisi"},
                new TimeZoneIdInfo(){key= "23",value="Iran Standard Time",des="(GMT+03:30) Tehran"},
                new TimeZoneIdInfo(){key= "24",value="Arabian Standard Time",des="(GMT+04:00) Abu Dhabi, Muscat"},
                new TimeZoneIdInfo(){key= "25",value="Azerbaijan Standard Time",des="(GMT+04:00) Baku"},
                new TimeZoneIdInfo(){key= "26",value="Mauritius Standard Time",des="(GMT+04:00) Port Louis"},
                new TimeZoneIdInfo(){key= "27",value="Caucasus Standard Time",des="(GMT+04:00) Yerevan"},
                new TimeZoneIdInfo(){key= "28",value="Afghanistan Standard Time",des="(GMT+04:30) Kabul"},
                new TimeZoneIdInfo(){key= "29",value="Ekaterinburg Standard Time",des="(GMT+05:00) Ekaterinburg"},
                new TimeZoneIdInfo(){key= "30",value="Pakistan Standard Time",des="(GMT+05:00) Islamabad, Karachi"},
                new TimeZoneIdInfo(){key= "31",value="West Asia Standard Time",des="(GMT+05:00) Tashkent"},
                new TimeZoneIdInfo(){key= "32",value="India Standard Time",des="(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi"},
                new TimeZoneIdInfo(){key= "33",value="Sri Lanka Standard Time",des="(GMT+05:30) Sri Jayawardenepura"},
                new TimeZoneIdInfo(){key= "34",value="Nepal Standard Time",des="(GMT+05:45) Kathmandu"},
                new TimeZoneIdInfo(){key= "35",value="N. Central Asia Standard Time",des="(GMT+06:00) Almaty, Novosibirsk"},
                new TimeZoneIdInfo(){key= "36",value="Central Asia Standard Time",des="(GMT+06:00) Astana, Dhaka"},
                new TimeZoneIdInfo(){key= "37",value="Myanmar Standard Time",des="(GMT+06:30) Yangon (Rangoon)"},
                new TimeZoneIdInfo(){key= "vi",value="SE Asia Standard Time",des="(GMT+07:00) Bangkok, Hanoi, Jakarta"},
                new TimeZoneIdInfo(){key= "39",value="North Asia Standard Time",des="(GMT+07:00) Krasnoyarsk"},
                new TimeZoneIdInfo(){key= "40",value="China Standard Time",des="(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi"},
                new TimeZoneIdInfo(){key= "41",value="North Asia East Standard Time",des="(GMT+08:00) Irkutsk, Ulaan Bataar"},
                new TimeZoneIdInfo(){key= "42",value="Singapore Standard Time",des="(GMT+08:00) Kuala Lumpur, Singapore"},
                new TimeZoneIdInfo(){key= "43",value="W. Australia Standard Time",des="(GMT+08:00) Perth"},
                new TimeZoneIdInfo(){key= "44",value="Taipei Standard Time",des="(GMT+08:00) Taipei"},
                new TimeZoneIdInfo(){key= "45",value="Tokyo Standard Time",des="(GMT+09:00) Osaka, Sapporo, Tokyo"},
                new TimeZoneIdInfo(){key= "46",value="Korea Standard Time",des="(GMT+09:00) Seoul"},
                new TimeZoneIdInfo(){key= "47",value="Yakutsk Standard Time",des="(GMT+09:00) Yakutsk"},
                new TimeZoneIdInfo(){key= "48",value="Cen. Australia Standard Time",des="(GMT+09:30) Adelaide"},
                new TimeZoneIdInfo(){key= "49",value="AUS Central Standard Time",des="(GMT+09:30) Darwin"},
                new TimeZoneIdInfo(){key= "50",value="E. Australia Standard Time",des="(GMT+10:00) Brisbane"},
                new TimeZoneIdInfo(){key= "51",value="AUS Eastern Standard Time",des="(GMT+10:00) Canberra, Melbourne, Sydney"},
                new TimeZoneIdInfo(){key= "52",value="West Pacific Standard Time",des="(GMT+10:00) Guam, Port Moresby"},
                new TimeZoneIdInfo(){key= "53",value="Tasmania Standard Time",des="(GMT+10:00) Hobart"},
                new TimeZoneIdInfo(){key= "54",value="Vladivostok Standard Time",des="(GMT+10:00) Vladivostok"},
                new TimeZoneIdInfo(){key= "55",value="Central Pacific Standard Time",des="(GMT+11:00) Magadan, Solomon Is., New Caledonia"},
                new TimeZoneIdInfo(){key= "56",value="New Zealand Standard Time",des="(GMT+12:00) Auckland, Wellington"},
                new TimeZoneIdInfo(){key= "57",value="Fiji Standard Time",des="(GMT+12:00) Fiji, Kamchatka, Marshall Is."},
                new TimeZoneIdInfo(){key= "58",value="Tonga Standard Time",des="(GMT+13:00) Nuku'alofa"},
                new TimeZoneIdInfo(){key= "59",value="Azores Standard Time",des="(GMT-01:00) Azores"},
                new TimeZoneIdInfo(){key= "60",value="Cape Verde Standard Time",des="(GMT-01:00) Cape Verde Is."},
                new TimeZoneIdInfo(){key= "61",value="Mid-Atlantic Standard Time",des="(GMT-02:00) Mid-Atlantic"},
                new TimeZoneIdInfo(){key= "62",value="E. South America Standard Time",des="(GMT-03:00) Brasilia"},
                new TimeZoneIdInfo(){key= "63",value="Argentina Standard Time",des="(GMT-03:00) Buenos Aires"},
                new TimeZoneIdInfo(){key= "64",value="SA Eastern Standard Time",des="(GMT-03:00) Georgetown"},
                new TimeZoneIdInfo(){key= "65",value="Greenland Standard Time",des="(GMT-03:00) Greenland"},
                new TimeZoneIdInfo(){key= "66",value="Montevideo Standard Time",des="(GMT-03:00) Montevideo"},
                new TimeZoneIdInfo(){key= "67",value="Newfoundland Standard Time",des="(GMT-03:30) Newfoundland"},
                new TimeZoneIdInfo(){key= "68",value="Atlantic Standard Time",des="(GMT-04:00) Atlantic Time (Canada)"},
                new TimeZoneIdInfo(){key= "69",value="SA Western Standard Time",des="(GMT-04:00) La Paz"},
                new TimeZoneIdInfo(){key= "70",value="Central Brazilian Standard Time",des="(GMT-04:00) Manaus"},
                new TimeZoneIdInfo(){key= "71",value="Pacific SA Standard Time",des="(GMT-04:00) Santiago"},
                new TimeZoneIdInfo(){key= "72",value="Venezuela Standard Time",des="(GMT-04:30) Caracas"},
                new TimeZoneIdInfo(){key= "73",value="SA Pacific Standard Time",des="(GMT-05:00) Bogota, Lima, Quito, Rio Branco"},
                new TimeZoneIdInfo(){key= "74",value="Eastern Standard Time",des="(GMT-05:00) Eastern Time (US & Canada)"},
                new TimeZoneIdInfo(){key= "75",value="US Eastern Standard Time",des="(GMT-05:00) Indiana (East)"},
                new TimeZoneIdInfo(){key= "76",value="Central America Standard Time",des="(GMT-06:00) Central America"},
                new TimeZoneIdInfo(){key= "77",value="Central Standard Time",des="(GMT-06:00) Central Time (US & Canada)"},
                new TimeZoneIdInfo(){key= "78",value="Central Standard Time (Mexico)",des="(GMT-06:00) Guadalajara, Mexico City, Monterrey"},
                new TimeZoneIdInfo(){key= "79",value="Canada Central Standard Time",des="(GMT-06:00) Saskatchewan"},
                new TimeZoneIdInfo(){key= "80",value="US Mountain Standard Time",des="(GMT-07:00) Arizona"},
                new TimeZoneIdInfo(){key= "81",value="Mountain Standard Time (Mexico)",des="(GMT-07:00) Chihuahua, La Paz, Mazatlan"},
                new TimeZoneIdInfo(){key= "82",value="Mountain Standard Time",des="(GMT-07:00) Mountain Time (US & Canada)"},
                new TimeZoneIdInfo(){key= "83",value="Pacific Standard Time",des="(GMT-08:00) Pacific Time (US & Canada)"},
                new TimeZoneIdInfo(){key= "84",value="Pacific Standard Time (Mexico)",des="(GMT-08:00) Tijuana, Baja California"},
                new TimeZoneIdInfo(){key= "85",value="Alaskan Standard Time",des="(GMT-09:00) Alaska"},
                new TimeZoneIdInfo(){key= "86",value="Hawaiian Standard Time",des="(GMT-10:00) Hawaii"},
                new TimeZoneIdInfo(){key= "87",value="Samoa Standard Time",des="(GMT-11:00) Midway Island, Samoa"},
                new TimeZoneIdInfo(){key= "88",value="Dateline Standard Time",des="(GMT-12:00) International Date Line West"},
            };
            return lst;
        }

        /// <summary>
        /// lay tu UTC -> tgian theo country code
        /// </summary>
        /// <param name="date">date input</param>
        /// <param name="country_code">vi</param>
        /// <returns></returns>
        public static DateTime GetDateTimeByCountry(DateTime date, string country_code) {
            var lst = ListTimeInfo();
            string strTimeInfo = "SE Asia Standard Time";
            foreach (var itm in lst) {
                if (itm.key == country_code)
                    strTimeInfo = itm.value;
            }
            DateTime dt;
            try
            {
                dt = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(date, TimeZoneInfo.Utc.Id, strTimeInfo); // utc-> desc tz :)
            }
            catch {
                dt = DateTime.MinValue; // gio min :D
            }
            return dt;
        }

        /// <summary>
        /// lay thoi gian tu UTC -> gio quoc gia mac dinh
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static DateTime GetTimeByCountryDefault(DateTime date)
        {
            return GetDateTimeByCountry(date, global_const.LANGUAGE_CODE_DEFAULT);
        }
        
    }
}
